package com.sky.mapper;

import com.sky.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;

@Mapper
public interface UserMapper {
    /**
     * 根据openid查询用户
     * @param openid
     * @return
     */
    @Select("select * from user where openid=#{openid}")
    User getByOpenid(String openid);

    /**
     * 插入数据
     * @param user
     */
    void insert(User user);

    /**
     * 根据主键查询用户
     * @param userId
     * @return
     */
    @Select("select * from user where id=#{userId}")
    User getById(Long userId);

    /**
     * 查询每天新增用户数量
     * @param beginTime
     * @param endTime
     * @return
     */
    @Select("select COUNT(id) from user where create_time < #{endTime} and create_time > #{beginTime} ")
    Integer selectNewCreateTime(LocalDateTime beginTime, LocalDateTime endTime);

    /**
     * 查询总用户数量
     * @param endTime
     * @return
     */
    @Select("select COUNT(id) from user where create_time < #{endTime} ")
     Integer selectUserCount(LocalDateTime endTime);
}
